package org.javagril.yuetong.controller.truck;

import org.javagril.yuetong.bean.RespBean;
import org.javagril.yuetong.bean.RespPageBean;
import org.javagril.yuetong.bean.Truck;
import org.javagril.yuetong.bean.TruckTeam;
import org.javagril.yuetong.service.TruckService;
import org.javagril.yuetong.service.TruckTeamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author QingtungTree
 * @Datetime: 2019/12/23
 * @Description:org.javagril.yuetong.controller.truck
 * @Version:
 */
@RestController
@RequestMapping("/truck")
public class TruckController {
    @Autowired
    TruckService truckService;/*对象注入*/
    @Autowired
    TruckTeamService truckTeamService;
    @GetMapping("/")
    public RespPageBean getAllTrucksByPage(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer size){
        return truckService.getAllTrucksByPage(page,size);
    }

    /*添加车辆 所需接口*/
    @GetMapping("/truckteam")
    public List<TruckTeam> getAllTruckTeam(){

        return truckTeamService.getAllTruckTeam();
    }

    @PostMapping("/")
    public RespBean addTruck(@RequestBody Truck truck){
        if (truckService.addTruck(truck)==1){
            return RespBean.ok("车辆信息添加成功...");
        }
        return RespBean.error("车辆信息添加失败...(￣、￣)");
    }

    /*修改接口*/
    @PutMapping("/")
    public RespBean updateTruck(@RequestBody Truck truck){
        if (truckService.updateTruck(truck)==1){
            return RespBean.ok("车辆信息编辑成功...");
        }
        return RespBean.error("车辆信息编辑失败...(￣、￣)");
    }

    /*删除接口*/
    @DeleteMapping("/{id}")
    public RespBean deleteTruckById(@PathVariable Integer id) {
        if (truckService.deleteTruckById(id) == 1) {
            return RespBean.ok("车辆信息删除成功...o(*￣▽￣*)ブ");
        }
        return RespBean.error("车辆信息删除失败...(￣、￣)");
    }
}
